/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Aguarde.java
 *
 * Created on 17/06/2010, 20:44:20
 */
package com.main.gui;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javazoom.jlgui.basicplayer.BasicPlayer;
import javazoom.jlgui.basicplayer.BasicPlayerException;

/**
 *
 * @author manchini
 */
public class Aguarde extends javax.swing.JFrame implements Runnable {

    private Thread thread;

    /**
     * Creates new form Aguarde
     */
    public Aguarde() {
        super();
        initComponents();
        this.setIconImage(new ImageIcon(getClass().getResource("/com/img/icon.png")).getImage());
    }

    public void intro() {
        try {
            BasicPlayer player = new BasicPlayer();
            player.open(getClass().getResource("/com/img/intro.mp3"));
            player.play();
        } catch (BasicPlayerException ex) {
            ex.printStackTrace(System.err);
        }
    }

    public void mostrar() {
        if (isVisible()) {
            String war = "Warning: essa tela já esta ativa.\n";
            try {
                System.err.write(war.getBytes());
            } catch (IOException ex) {
                Logger.getLogger(Aguarde.class.getName()).log(Level.SEVERE, null, ex);
            }
            return;
        }
        setVisible(true);
        standBy();
    }

    public void ocultar() {
        thread.interrupt();
        thread = null;
        dispose();
    }

    private void standBy() {
        thread = new Thread(this);
        thread.start();
    }

    @Override
    @SuppressWarnings("SleepWhileInLoop")
    public void run() {
        int count = 0;
        while (true) {
            try {
                count++;
                jProgressBar1.setValue(count * 10);
                switch (count) {
                    case 1:
                        jProgressBar1.setString("Aguarde...");
                        break;
                    case 4:
                        jProgressBar1.setString("Aguarde Mais Um Pouco");
                        break;
                    case 7:
                        jProgressBar1.setString("Ta Um Pouco Demorado");
                        break;
                    case 10:
                        jProgressBar1.setString("ZZZZZzzzzzZZZZZZzzz");
                        break;
                    case 13:
                        jProgressBar1.setString("RRuuuuuu.... uiiiiiiii");
                        break;
                    case 16:
                        jProgressBar1.setString("Não Aperte Ctrl+Alt+Del");
                        break;
                    case 19:
                        jProgressBar1.setString("Eu Consigo....");
                        break;
                    case 22:
                        jProgressBar1.setString("Ta Quase conseguindo...");
                        break;
                    case 25:
                        jProgressBar1.setString("Ou Não");
                        break;
                    case 28:
                        jProgressBar1.setString("Espere um pouco mais...");
                        break;
                    case 31:
                        jProgressBar1.setString("Está difícil...");
                        break;
                    case 34:
                        jProgressBar1.setString("To Quase Desistindo");
                        break;
                    case 37:
                        jProgressBar1.setString("Sou Brasileiro");
                        break;
                    case 40:
                        jProgressBar1.setString("Não Desisto Nunca");
                        break;
                    case 50:
                        jProgressBar1.setString("Tá Bom Pode Fecha.");
                        break;
                    default:
                        break;

                }
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(Aguarde.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jProgressBar1 = new javax.swing.JProgressBar();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Crepz Player");
        setMinimumSize(new java.awt.Dimension(310, 306));
        setResizable(false);
        setUndecorated(true);
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        jPanel3.setBackground(new java.awt.Color(0, 0, 0));
        jPanel3.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel3.setMinimumSize(new java.awt.Dimension(306, 306));
        jPanel3.setLayout(new java.awt.BorderLayout());

        jPanel2.setBackground(new java.awt.Color(0, 0, 0));
        jPanel2.setPreferredSize(new java.awt.Dimension(397, 50));

        jProgressBar1.setPreferredSize(new java.awt.Dimension(250, 30));
        jProgressBar1.setStringPainted(true);
        jPanel2.add(jProgressBar1);

        jPanel3.add(jPanel2, java.awt.BorderLayout.SOUTH);

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/img/capa.jpg"))); // NOI18N
        jPanel1.add(jLabel1, java.awt.BorderLayout.CENTER);

        jPanel3.add(jPanel1, java.awt.BorderLayout.PAGE_START);

        getContentPane().add(jPanel3);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-302)/2, (screenSize.height-384)/2, 302, 384);
    }// </editor-fold>//GEN-END:initComponents
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JProgressBar jProgressBar1;
    // End of variables declaration//GEN-END:variables
}
